package Search.Binary;

public class BinarySearch {
    public static void main(String[] args) {
        int[] arr = new int[]{5,12,34,56,67,89,91,98,100,239};
        int left = 0;
        int right = arr.length - 1;
        int target = 12;
        boolean flag = true;
        while(left <= right) {
            int mid = (right - left) / 2;
            if(arr[mid]==target) {
                System.out.println("找到了，索引为" + mid);
                flag = false;
                break;
            }
            else if (arr[mid] > target) {
                right = mid;
            }
            else if (arr[mid] < target) {
                left = mid;
            }
        }

        if(flag)
            System.out.println("没找到");
    }
}
